<template>
  <div title="" class="sysmDetails">
    <h3>{{ title }}</h3>
    <div class="rightbox">
      <el-select
        :placeholder="$t('weekendShow.placeholder')"
        v-model="valueWeek"
        @change="workshopChange"
      >
        <el-option
          v-for="item in workshopList"
          :key="item"
          :label="item"
          :value="item"
        >
        </el-option>
      </el-select>
    </div>

    <dv-scroll-board class="dv-scr-board" :config="config" />
  </div>
</template>

<script>
import moment from "moment";
export default {
  name: "weekendShow",
  components: {},
  props: {
    parentDatax: {
      type: Array,
      default: [],
    },
    parentDatay: {
      type: Array,
      default: [],
    },
    title: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      title: "",
      valueWeek: "WK01",
      workshopList: [],
      config: {
        header: [
          this.$t('weekendShow.header.machineNumber'),
          this.$t('weekendShow.header.monday'),
          this.$t('weekendShow.header.tuesday'),
          this.$t('weekendShow.header.wednesday'),
          this.$t('weekendShow.header.thursday'),
          this.$t('weekendShow.header.friday'),
          this.$t('weekendShow.header.saturday'),
          this.$t('weekendShow.header.weekCapacity'),
        ],
        data: [],
        rowNum: 12, //表格行数
        headerHeight: 55,
        headerBGC: "#131c38", //表头
        oddRowBGC: "#14314d", //奇数行
        evenRowBGC: "", //偶数行
        columnWidth: [150, 130, 130, 130, 130, 130, 130, 150],
        align: [
          "center",
          "center",
          "center",
          "center",
          "center",
          "center",
          "center",
          "center",
        ],
      },
      firstCell: [],
    };
  },
  computed: {},
  watch: {
    parentDatax: {
      handler(val) {
        this.firstCell = val;
        this.init();
      },
      immediate: true,
      deep: true,
    },
    parentDatay: {
      handler(val) {},
      immediate: true,
      deep: true,
    },
  },
  mounted() {
    this.init();
  },
  created() {
    this.workshopList = [];
    for (let i = 1; i <= 9; i++) {
      this.workshopList.push("WK0" + i);
    }
    for (let i = 10; i <= this.getWeekNumber(); i++) {
      this.workshopList.push("WK" + i);
    }
  },
  methods: {
    //获取周数
    getWeekNumber(date) {
      date = typeof date !== "undefined" ? date : new Date();
      var currentDate = new Date(
        date.getFullYear(),
        date.getMonth(),
        date.getDate()
      );
      var firstDayOfYear = new Date(currentDate.getFullYear(), 0, 1);
      var pastDaysOfYear = (currentDate - firstDayOfYear) / 86400000;
      var firstWeek = this.getFirstWeek(firstDayOfYear);

      if (firstWeek.getDay() !== 4) {
        currentDate -= (7 - firstWeek.getDay()) * 86400000;
      }

      return Math.floor((currentDate - firstDayOfYear) / 604800000) + 1;
    },
    getFirstWeek(date) {
      var thursday = new Date(date.getFullYear(), 0, 4);
      var firstWeek = new Date(
        thursday.getFullYear(),
        0,
        1 + (thursday.getDay() || -7)
      );
      return firstWeek;
    },

    //下拉框切换
    workshopChange() {
      this.init();
    },
    getRandomInt(min, max) {
      min = Math.ceil(min);
      max = Math.floor(max);
      return Math.floor(Math.random() * (max - min + 1)) + min;
    },
    init() {
      let data = [];
      this.firstCell.forEach((item) => {
        data.push([
          item,
          this.getRandomInt(800, 1200),
          this.getRandomInt(800, 1200),
          this.getRandomInt(800, 1200),
          this.getRandomInt(800, 1200),
          this.getRandomInt(800, 1200),
          this.getRandomInt(800, 1200),
          this.getRandomInt(5800, 72000),
        ]);
      });
      this.config.data = data;
      this.config = { ...this.config };
    },
  },
};
</script>

<style lang="scss" scoped>
h3 {
  text-align: center;
  font-weight: 700;
  border-bottom: 2px solid #4a6bd6;
  padding-bottom: 10px;
  line-height: 45px;
  font-size: 24px;
  margin: 0;
}
.sysmDetails {
  width: 1100px;
  height: 760px;
  border-radius: 30px;
  padding-top: 10px;
  background: linear-gradient(to right, #0f1836, #14314d);
}

::v-deep .dv-scroll-board {
  width: 1090px;
  height: 680px;
  margin-left: 5px;
  .header {
    color: rgb(122, 182, 206);
    font-size: 18px;
    font-weight: 700;
    :nth-child(1) {
      color: #1d96fa;
    }
  }
  .rows {
    .row-item {
      color: rgb(122, 182, 206);
      font-size: 17px;
      height: 42px;
      line-height: 42px;
      .ceil:nth-child(1) {
        color: #1d96fa;
        font-size: 18px;
      }
    }
  }
}

.rightbox {
  width: 200px;
  // position: absolute;
  float: right;
  margin-right: 20px;
  margin-top: -50px;
  span {
    font-size: 20px;
    color: #8993f2;
  }
}
//下拉框
::v-deep .el-input__inner {
  background-color: transparent !important;
  color: #8993f2;
  height: 35px !important;
  font-size: 16px !important;
}
/**修改边框和字体颜色 */
::v-deep .el-select {
  position: relative;
  width: 160px;
  .el-input {
    input {
      font-size: 15px !important;
      height: 35px !important;
      border-color: rgba(44, 137, 229, 0.5);
      color: #8993f2 !important;
    }
  }
}
</style>
